<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>tree模板</title>
    <script type="text/javascript" src="${staticPath}js/jquery.min.js"></script>
    <link href="${staticPath}js/zTree_v3/css/zTreeStyle/zTreeStyle.css"
          rel="stylesheet" type="text/css" />
    <script type="text/javascript"
            src="${staticPath}js/zTree_v3/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript"
            src="${staticPath}js/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript"
            src="${staticPath}js/zTree_v3/js/jquery.ztree.excheck-3.5.js"></script>
    <script type="text/javascript"
            src="${staticPath}js/zTree_v3/js/jquery.ztree.exedit-3.5.js"></script>
    <style>
       html,body{
           height:100%;
       }
   </style>
</head>
<body >
     <div style="height:98%;width: 20%;float: left">
         <ul id="treeData" class="ztree"></ul>
     </div>
     <iframe width="80%" height="98%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="auto" allowtransparency="yes" id="rightFrame"

     >
     </iframe>
</body>

<script type="text/javascript">

    var nodeStatusMap = {};

    var selectedNodes = [];

    var isInit = false;

    $(function() {
        $.post("${basePath}/ms/x/${modelConfig.namespace}/ztreeData", {},
            function(jsonStr) {
                $.fn.zTree.init($("#treeData"), setting, jsonStr);
                var treeObj = $.fn.zTree.getZTreeObj("treeData");
                //获取节点
                var nodes = treeObj.getNodes();
                if (nodes.length > 0 ) {
                    var node = nodes[0];
                    treeObj.selectNode(node);
                    treeObj.expandAll(false);
                    treeObj.expandNode(node, true, false, false);
                    refreshRight(node.id,node.name);
                }
            }, "json");
    });

    //重新加载数据
    function reloadData(){
        var treeObj = $.fn.zTree.getZTreeObj("treeData");
        var nodes = treeObj.getSelectedNodes();
        if (nodes.length>0) {
            treeObj.reAsyncChildNodes(nodes[0], "refresh");
        }
    }
</script>
<script type="text/javascript">

    //ZTree 配置
    var setting = {
        data : {
            simpleData : {
                idKey : "${modelConfig.pkey}", //主键id
                pIdKey : "${keySett.fidkey}",//父id字段
                name : "${keySett.namekey}",//显示哪个字段
                enable : true
            }
        },
        async:{
            autoParam:["pid"],
            enable:true,
            type:"get",
            url:'${basePath}/ms/x/${modelConfig.namespace}/ztreeData',
        },
        callback : {
            onClick : clickSelect,
            beforeDrag : beforeDrags,
        }
    };

    <% if(isNotEmpty(parameter.type)){
        var tempUrl = listUrlSettMap[parameter.type];
    %>
    var listUrl ="${tempUrl}";
    <%}else{%>
    var listUrl ="${basePath}/ms/pagex/${modelConfig.namespace}_list.jsp?${keySett.fidkey}=";
     <%}%>
    function clickSelect(event, treeId, treeNode, clickFlag) {
        refreshRight(treeNode.id,treeNode.name)
    }
    function beforeDrags(treeId, treeNodes) {
        return false;
    }

    function refreshRight(_id,_name){
        $('#rightFrame').attr('src',listUrl + _id + '&name=' + _name );
    }
</script>
</html>